<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the YAML representation of a value</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.yaml-emit-file.html">« yaml_emit_file</a></li>
      <li style="float: right;"><a href="function.yaml-parse-file.html">yaml_parse_file »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.yaml.html">Yaml 函数</a></li>
    <li>Returns the YAML representation of a value</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.yaml-emit" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">yaml_emit</h1>
  <p class="verinfo">(PECL yaml &gt;= 0.5.0)</p><p class="refpurpose"><span class="refname">yaml_emit</span> &mdash; <span class="dc-title">Returns the YAML representation of a value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.yaml-emit-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>yaml_emit</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$data</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$encoding</code><span class="initializer"> = YAML_ANY_ENCODING</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$linebreak</code><span class="initializer"> = YAML_ANY_BREAK</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$callbacks</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Generate a YAML representation of the provided <code class="parameter">data</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.yaml-emit-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">data</code></dt>

     <dd>

      <p class="para">
       The <code class="parameter">data</code> being encoded. Can be any type except
       a <span class="type">resource</span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">encoding</code></dt>

     <dd>

      <p class="para">
       Output character encoding chosen from
       <strong><code>YAML_ANY_ENCODING</code></strong>,
       <strong><code>YAML_UTF8_ENCODING</code></strong>,
       <strong><code>YAML_UTF16LE_ENCODING</code></strong>,
       <strong><code>YAML_UTF16BE_ENCODING</code></strong>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">linebreak</code></dt>

     <dd>

      <p class="para">
       Output linebreak style chosen from
       <strong><code>YAML_ANY_BREAK</code></strong>,
       <strong><code>YAML_CR_BREAK</code></strong>,
       <strong><code>YAML_LN_BREAK</code></strong>,
       <strong><code>YAML_CRLN_BREAK</code></strong>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">callbacks</code></dt>

     <dd>

      <p class="para">
       Content handlers for emitting YAML nodes. Associative <span class="type">array</span>
       of classname =&gt; <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> mappings. See
       <a href="yaml.callbacks.emit.html" class="link">emit callbacks</a> for more
       details.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.yaml-emit-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a YAML encoded <span class="type">string</span> on success.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.yaml-emit-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL yaml 1.1.0</td>
       <td>
        The <code class="parameter">callbacks</code> parameter was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.yaml-emit-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3856">
    <p><strong>示例 #1 <span class="function"><strong>yaml_emit()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$addr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"given"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Chris"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"family"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Dumars"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"address"</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"lines"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"458&nbsp;Walkman&nbsp;Dr.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Suite&nbsp;#292"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"city"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Royal&nbsp;Oak"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"state"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"MI"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"postal"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">48046</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;);<br /></span><span style="color: #0000BB">$invoice&nbsp;</span><span style="color: #007700">=&nbsp;array&nbsp;(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"invoice"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">34843</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"date"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">980208000</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"bill-to"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$addr</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"ship-to"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$addr</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"product"</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"sku"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"BL394D"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"quantity"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"description"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Basketball"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"price"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">450</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"sku"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"BL4438H"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"quantity"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"description"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Super&nbsp;Hoop"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"price"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">2392</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"tax"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">251.42</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"total"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">4443.52</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"comments"</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Late&nbsp;afternoon&nbsp;is&nbsp;best.&nbsp;Backup&nbsp;contact&nbsp;is&nbsp;Nancy&nbsp;Billsmer&nbsp;@&nbsp;338-4338."</span><span style="color: #007700">,<br />&nbsp;&nbsp;);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">yaml_emit</span><span style="color: #007700">(</span><span style="color: #0000BB">$invoice</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(628) &quot;---
invoice: 34843
date: 980208000
bill-to:
  given: Chris
  family: Dumars
  address:
    lines: |-
      458 Walkman Dr.
              Suite #292
    city: Royal Oak
    state: MI
    postal: 48046
ship-to:
  given: Chris
  family: Dumars
  address:
    lines: |-
      458 Walkman Dr.
              Suite #292
    city: Royal Oak
    state: MI
    postal: 48046
product:
- sku: BL394D
  quantity: 4
  description: Basketball
  price: 450
- sku: BL4438H
  quantity: 1
  description: Super Hoop
  price: 2392
tax: 251.420000
total: 4443.520000
comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.
...
&quot;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.yaml-emit-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.yaml-emit-file.html" class="function" rel="rdfs-seeAlso">yaml_emit_file()</a> - Send the YAML representation of a value to a file</span></li>
    <li class="member"><span class="function"><a href="function.yaml-parse.html" class="function" rel="rdfs-seeAlso">yaml_parse()</a> - Parse a YAML stream</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>